// State variables consistently shared by PC host and all tracker processors.
// This file is also included in the firmware projects.

#ifndef __TRKDRV_STATE_H
#define __TRKDRV_STATE_H
#endif

#ifdef __cplusplus
#define EXTERN_TYPE extern "C"
#else
#define EXTERN_TYPE extern
#endif

#ifdef TRKDRV_STATE_VARS_IMPLEMENT_HERE
#define EXTERN_TYPE
#endif

EXTERN_TYPE unsigned char trk_device_mode;
EXTERN_TYPE unsigned char trk_device_n_nodes;
EXTERN_TYPE unsigned char trk_device_n_cycle_integration;
EXTERN_TYPE unsigned char trk_device_pwm_h;
EXTERN_TYPE unsigned char trk_device_pwm_l;
EXTERN_TYPE unsigned char trk_device_ph1_h; 
EXTERN_TYPE unsigned char trk_device_ph1_l;
EXTERN_TYPE unsigned char trk_device_ph2_h; 
EXTERN_TYPE unsigned char trk_device_ph2_l;

// constant definitions for relevant variables.
#define DEVICE_MODE_NORMAL 0
#define DEVICE_MODE_AUTONOMOUS_SINGLE_NODE_LOOP 1

EXTERN_TYPE void trkdrv_set_default_vars_explicit(void);

#ifdef TRKDRV_STATE_VARS_IMPLEMENT_HERE
void trkdrv_set_default_vars_explicit(void)							\
{																	\
	trk_device_mode=DEVICE_MODE_AUTONOMOUS_SINGLE_NODE_LOOP;		\
	trk_device_n_nodes=1;											\
	trk_device_n_cycle_integration=10;								\
	trk_device_pwm_h=0;												\
	trk_device_pwm_l=31;											\
	trk_device_ph1_h=0;												\
	trk_device_ph1_l=21;											\
	trk_device_ph2_h=0;												\
	trk_device_ph2_l=5;												\
}
#endif